/*****************************************************************************/
/**
 *  @file   Argument.cpp
 *  @author Naohisa Sakamoto
 */
/*----------------------------------------------------------------------------
 *
 *  Copyright (c) Visualization Laboratory, Kyoto University.
 *  All rights reserved.
 *  See http://www.viz.media.kyoto-u.ac.jp/kvs/copyright/ for details.
 *
 *  $Id$
 */
/*****************************************************************************/
#include "Argument.h"


Argument::Argument( int argc, char** argv )
{
    m_command = Command( new kvs::CommandLine( argc, argv ) );
    m_command->addHelpOption();
    m_command->addOption( "output", "Output directory (default: \".\")", 1 );
    m_command->addOption( "divide", "Number of divisions. (default: 1)", 1 );
    m_command->addOption( "byte", "Output the data as byte data. (optional)" );
    m_command->addOption( "verbose", "Display the processing information. (optional)" );
    m_command->addValue( "Input file or directory." );
}

bool Argument::parse()
{
    return m_command->parse();
}

bool Argument::hasByteOption() const
{
    return m_command->hasOption( "byte" );
}

bool Argument::hasVerboseOption() const
{
    return m_command->hasOption( "verbose" );
}

size_t Argument::numberOfDivisions() const
{
    if ( !m_command->hasOption( "divide" ) ) return 1;
    else return m_command->optionValue<size_t>( "divide" );
}

std::string Argument::output() const
{
    if ( !m_command->hasOption( "output" ) ) return ".";
    else return m_command->optionValue<std::string>( "output" );
}

std::string Argument::input() const
{
    return m_command->value<std::string>();
}

void Argument::print( std::ostream& os, const kvs::Indent& indent ) const
{
    os << indent << "Input: " << input() << std::endl;
    os << indent << "Output: " << output() << std::endl;
    os << indent << "Number of divisions: " << numberOfDivisions() << std::endl;
    os << indent << "Byte option: " << std::boolalpha << hasByteOption() << std::endl;
    os << indent << "Verbose option: " << std::boolalpha << hasVerboseOption() << std::endl;
}
